﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BHXH.Frm.Frm
{
    public partial class ThongTinDonVi : UserControl
    {
        ThongTinChung usercontrol_Thongtinchung;
        ThongTinCoQuanQL usercontrol_Thongtincoquanquanly;
        ThongTinXuatHoaDon usercontrol_Thongtinxuathoadon;
        public ThongTinDonVi()
        {
            InitializeComponent();

            usercontrol_Thongtinchung = new ThongTinChung();
            showControl_ThongTinChung(usercontrol_Thongtinchung);

            usercontrol_Thongtincoquanquanly = new ThongTinCoQuanQL();
            showControl_ThongTinCoQuanQL(usercontrol_Thongtincoquanquanly);

            usercontrol_Thongtinxuathoadon = new ThongTinXuatHoaDon();
            showControl_ThongTinXuatHoaDon(usercontrol_Thongtinxuathoadon);

            setEnbale(true);
        }

        public void setEnbale(bool b)
        {
            BtnSua.Enabled = b;
            btnLuu.Enabled = !b;
            btnBoQua.Enabled = !b;

        }
        private void showControl_ThongTinChung(System.Windows.Forms.Control obj)
        {
            panel_Thongtinchung.Controls.Clear();
            obj.Dock = DockStyle.Fill;
            panel_Thongtinchung.Controls.Add(obj);
            panel_Thongtinchung.Controls[obj.Name].Focus();
        }

        private void showControl_ThongTinCoQuanQL(System.Windows.Forms.Control obj)
        {
            panel_ThongTinCoQuanQuanLy.Controls.Clear();
            obj.Dock = DockStyle.Fill;
            panel_ThongTinCoQuanQuanLy.Controls.Add(obj);
            panel_ThongTinCoQuanQuanLy.Controls[obj.Name].Focus();
        }

        private void showControl_ThongTinXuatHoaDon(System.Windows.Forms.Control obj)
        {
            panel_ThongTinXuatHoaDon.Controls.Clear();
            obj.Dock = DockStyle.Fill;
            panel_ThongTinXuatHoaDon.Controls.Add(obj);
            panel_ThongTinXuatHoaDon.Controls[obj.Name].Focus();
        }
        void Exit_App()
        {
            if (DialogResult.Yes == MessageBox.Show("Bạn có chắc chắn thoát không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                Application.ExitThread();
            }
        }
        private void ultraTabControl1_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.F2:
                    setEnbale(false);
                    if (thongtinchung_TabPage.Tab.Active)
                    {
                        usercontrol_Thongtinchung.suaclick();
                    }
                    else if (thongtincoquan_TabPage.Tab.Active)
                    {
                
                    }
                    else if (thongtinxuathd_TabPage.Tab.Active)
                    {
                        usercontrol_Thongtinxuathoadon.btnSua_Click();
                    }
                    break;
                case Keys.F5:
                    setEnbale(true);
                    if (thongtinchung_TabPage.Tab.Active)
                    {
                        usercontrol_Thongtinchung.btnLuu_Click();
                    }
                    else if (thongtincoquan_TabPage.Tab.Active)
                    {

                    }
                    else if (thongtinxuathd_TabPage.Tab.Active)
                    {
                        usercontrol_Thongtinxuathoadon.btnLuu_click();
                    }
                    break;

                case Keys.Escape:
                    setEnbale(true);
                    if (thongtinchung_TabPage.Tab.Active)
                    {
                        usercontrol_Thongtinchung.btnBoqua_click();
                    }
                    else if (thongtincoquan_TabPage.Tab.Active)
                    {

                    }
                    else if (thongtinxuathd_TabPage.Tab.Active)
                    {
                        usercontrol_Thongtinxuathoadon.btnBoQua_Click();
                    }
                    break;
                case Keys.F12:
                    Exit_App();
                    break;
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Exit_App();
        }

        private void BtnSua_Click(object sender, EventArgs e)
        {
            setEnbale(false);
            if (thongtinchung_TabPage.Tab.Active)
            {
                usercontrol_Thongtinchung.suaclick();
            }
            else if (thongtincoquan_TabPage.Tab.Active)
            {
                
            }
            else if (thongtinxuathd_TabPage.Tab.Active)
            {
                usercontrol_Thongtinxuathoadon.btnSua_Click();
            }
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            setEnbale(true);
            if (thongtinchung_TabPage.Tab.Active)
            {
                usercontrol_Thongtinchung.btnLuu_Click();
            }
            else if (thongtincoquan_TabPage.Tab.Active)
            {

            }
            else if (thongtinxuathd_TabPage.Tab.Active)
            {
                usercontrol_Thongtinxuathoadon.btnLuu_click();
            }
        }

        private void btnBoQua_Click(object sender, EventArgs e)
        {
            setEnbale(true);
            if (thongtinchung_TabPage.Tab.Active)
            {
                usercontrol_Thongtinchung.btnBoqua_click();
            }
            else if (thongtincoquan_TabPage.Tab.Active)
            {

            }
            else if (thongtinxuathd_TabPage.Tab.Active)
            {
                usercontrol_Thongtinxuathoadon.btnBoQua_Click();
            }
        }
    }
}
